package simple

// https://leetcode.cn/problems/middle-of-the-linked-list/description/?envType=problem-list-v2&envId=linked-list&difficulty=EASY
// 876 链表的中间节点
/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func middleNode(head *ListNode) *ListNode {
	if head == nil {
		return head
	}

	cnt := 0
	cur := head
	for cur != nil {
		cnt++
		cur = cur.Next
	}

	v := cnt / 2 //
	cur = head
	for i := 0; i < v; i++ {
		cur = cur.Next
	}
	return cur
}
